<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>社区宠物管理系统 - 登录</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background: url('imgs/2.png') no-repeat center center fixed;
            background-size: cover;
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
            position: relative;
        }

        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0);
            z-index: 1;
        }

        .login-container {
            width: 900px;
            height: 600px;
            background: white;
            border-radius: 20px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
            overflow: hidden;
            display: flex;
            animation: fadeInUp 0.8s ease-out;
            position: relative;
            z-index: 2;
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .left-panel {
            flex: 1;
            background: linear-gradient(135deg, #FFE4E1 0%, #FFF8DC 100%);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }

        .left-panel::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255, 182, 193, 0.3) 0%, transparent 70%);
            animation: float 6s ease-in-out infinite;
        }

        @keyframes float {
            0%, 100% { transform: translateY(0px) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(180deg); }
        }

        .pet-image {
            width: 300px;
            height: 300px;
            background-size: contain;
            background-repeat: no-repeat;
            background-position: center;
            z-index: 2;
            animation: bounce 2s ease-in-out infinite;
            transition: background-image 0.5s ease-in-out;
            /* 设置默认背景图片，防止加载失败 */
            background-image: url('imgs/10.png');
        }

        @keyframes bounce {
            0%, 20%, 50%, 80%, 100% {
                transform: translateY(0);
            }
            40% {
                transform: translateY(-10px);
            }
            60% {
                transform: translateY(-5px);
            }
        }

        .pet-title {
            font-size: 2.5rem;
            color: #FF6B6B;
            font-weight: bold;
            margin-top: 20px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
            z-index: 2;
        }

        .pet-subtitle {
            font-size: 1.1rem;
            color: #8B4513;
            margin-top: 10px;
            z-index: 2;
        }

        .right-panel {
            flex: 1;
            padding: 60px 50px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            background: white;
        }

        .login-header {
            text-align: center;
            margin-bottom: 40px;
        }

        .login-header h2 {
            font-size: 2rem;
            color: #333;
            margin-bottom: 10px;
            font-weight: 600;
        }

        .login-header p {
            color: #666;
            font-size: 0.9rem;
        }

        .form-group {
            margin-bottom: 25px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 500;
            font-size: 0.9rem;
        }

        .form-group i {
            margin-right: 8px;
            color: #FF6B6B;
        }

        .input-wrapper {
            position: relative;
        }

        .form-group input {
            width: 100%;
            padding: 15px 20px;
            border: 2px solid #E8E8E8;
            border-radius: 10px;
            font-size: 1rem;
            transition: all 0.3s ease;
            background: #F8F9FA;
        }

        .form-group input:focus {
            outline: none;
            border-color: #FF6B6B;
            background: white;
            box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.1);
        }

        .form-group input::placeholder {
            color: #999;
        }

        .login-btn {
            width: 100%;
            padding: 15px;
            background: linear-gradient(135deg, #FF6B6B 0%, #FF8E8E 100%);
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 10px;
            box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
        }

        .login-btn:hover {
            background: linear-gradient(135deg, #FF5252 0%, #FF7575 100%);
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
        }

        .login-btn:active {
            transform: translateY(0);
        }

        .error-message {
            background: #FFE6E6;
            color: #D32F2F;
            padding: 12px 15px;
            border-radius: 8px;
            margin-top: 15px;
            border-left: 4px solid #D32F2F;
            font-size: 0.9rem;
        }

        .error-message i {
            margin-right: 8px;
        }

        .decorative-paws {
            position: absolute;
            font-size: 1.5rem;
            color: rgba(255, 107, 107, 0.2);
            animation: rotate 8s linear infinite;
        }

        .paw-1 {
            top: 20px;
            right: 30px;
            animation-delay: 0s;
        }

        .paw-2 {
            bottom: 30px;
            right: 20px;
            animation-delay: 2s;
        }

        .paw-3 {
            top: 50%;
            right: 10px;
            animation-delay: 4s;
        }

        @keyframes rotate {
            from {
                transform: rotate(0deg);
            }
            to {
                transform: rotate(360deg);
            }
        }

        @media (max-width: 768px) {
            .login-container {
                width: 95%;
                height: 90vh;
                flex-direction: column;
            }

            .left-panel {
                height: 40%;
            }

            .pet-image {
                width: 200px;
                height: 200px;
            }

            .pet-title {
                font-size: 1.8rem;
            }

            .right-panel {
                padding: 40px 30px;
            }
        }
    </style>
</head>
<body>
<div class="login-container">
    <!-- 左侧面板 -->
    <div class="left-panel">
        <div class="pet-image" id="petImage"></div>
        <h1 class="pet-title">社区宠物管理</h1>
        <p class="pet-subtitle">给每个小生命一个温暖的家</p>

        <!-- 装饰性爪印 -->
        <i class="fas fa-paw decorative-paws paw-1"></i>
        <i class="fas fa-paw decorative-paws paw-2"></i>
        <i class="fas fa-paw decorative-paws paw-3"></i>
    </div>

    <!-- 右侧登录表单 -->
    <div class="right-panel">
        <div class="login-header">
            <h2>用户登录</h2>
            <p>欢迎回到我们的宠物社区</p>
        </div>

        <form method="post" accept-charset="UTF-8" action="${pageContext.request.contextPath}/login">
            <div class="form-group">
                <label><i class="fas fa-user"></i> 用户名</label>
                <input type="text" name="username" required placeholder="请输入用户名">
            </div>

            <div class="form-group">
                <label><i class="fas fa-lock"></i> 密码</label>
                <input type="password" name="password" required placeholder="请输入密码">
            </div>

            <button type="submit" class="login-btn">
                <i class="fas fa-sign-in-alt"></i> 登录系统
            </button>
        </form>

        <!-- 注册链接 -->
        <div style="text-align: center; margin-top: 20px;">
            <p style="color: #666; font-size: 0.9rem;">
                还没有账户？
                <a href="${pageContext.request.contextPath}/register.jsp"
                   style="color: #FF6B6B; text-decoration: none; font-weight: 500;">
                    立即注册
                </a>
            </p>
        </div>
        <c:if test="${not empty sessionScope.error}">
            <div class="error-message">
                <i class="fas fa-exclamation-triangle"></i> ${sessionScope.error}
            </div>

            <%-- 显示一次错误后立即清除 --%>
            <%
                session.removeAttribute("error");
            %>
        </c:if>
    </div>
</div>

<script>

    function setRandomPetImage() {
        console.log('开始设置随机图片...');

        // 生成10-28之间的随机数
        var randomNumber = Math.floor(Math.random() * 33) + 10;
        console.log('生成的随机数: ' + randomNumber);

        // 获取图片元素
        var petImage = document.getElementById('petImage');

        if (petImage && randomNumber) {
            // 设置随机背景图片
            var imageUrl = 'imgs/' + randomNumber + '.png';
            petImage.style.backgroundImage = 'url(' + imageUrl + ')';

            console.log('当前显示的图片: ' + randomNumber + '.png');
            console.log('完整图片路径: ' + imageUrl);
        } else {
            console.log('元素或随机数有问题');
            console.log('petImage: ' + petImage);
            console.log('randomNumber: ' + randomNumber);
        }
    }

    // 页面加载完成后执行
    document.addEventListener('DOMContentLoaded', setRandomPetImage);
</script>
</body>
</html>